package com.zis.platform.controller;

import com.alibaba.fastjson.JSON;
import com.zis.core.SearchParams;
import com.zis.platform.model.DictionaryType;
import com.zis.platform.service.IDictTypeInter;
import org.beetl.sql.core.engine.PageQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * Create by wangshen 2017/12/25
 */
@RestController
@RequestMapping("/api/sys/dict/type")
public class DictTypeController {

    @Autowired
    private IDictTypeInter dictTypeInter;

    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public PageQuery<DictionaryType> findByPage(@RequestBody SearchParams params) throws Exception {
        return dictTypeInter.findByPage(params);
    }

    @RequestMapping(value = "/save", method = RequestMethod.POST)
    @ResponseBody
    public String insert(HttpServletRequest request, @RequestBody DictionaryType dictionaryType) throws Exception {
        dictionaryType.setCreateUser(request.getAttribute("code").toString());
        return dictTypeInter.insert(dictionaryType);
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public String update(HttpServletRequest request, @RequestBody DictionaryType dictionaryType) throws Exception {
        dictionaryType.setUpdateUser(request.getAttribute("code").toString());
        return dictTypeInter.update(dictionaryType);
    }

    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    @ResponseBody
    public String delete(@PathVariable("id") String id) throws Exception{
        return dictTypeInter.delete(id);
    }
}
